#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int depth(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    int  left = depth(root->left);
    int right = depth(root->right);
    return left > right ? left + 1 : right + 1;
}
bool isBalanced(struct TreeNode* root) {
    if (root == NULL)
    {
        return true;
    }
    int a = depth(root->left);
    int b = depth(root->right);
    int ret = a > b ? a - b : b - a;
    if (ret > 1)
    {
        return false;
    }
    return isBalanced(root->left) && isBalanced(root->right);

}